package com.china.utils;

import android.app.Activity;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

/**
 * 获取手机屏幕的宽高
 * 
 * @author Luke
 *
 */
public final class ScreenUtil {
  private ScreenUtil() {
    throw new UnsupportedOperationException("cannot be instantiated");
  }

  /**
   * 获取屏幕中控件底部位置的高度--即控件底部的Y点
   * 
   * @return
   */
  public static int getScreenViewBottomHeight(View view) {
    return view.getBottom();
  }

  /**
   * 获取屏幕中控件顶部位置的高度--即控件底部的Y点
   * 
   * @return
   */
  public static int getScreenViewTopHeight(View view) {
    return view.getTop();
  }

  /**
   * 获得屏幕宽度
   * 
   * @param context
   * @return
   */
  public final static int getScreenWidth(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics outMetrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(outMetrics);

    return outMetrics.widthPixels;
  }

  /**
   * 获得屏幕高度
   * 
   * @param context
   * @return
   */
  public final static int getScreenHeight(Context context) {
    WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics outMetrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(outMetrics);

    return outMetrics.heightPixels;
  }

  /**
   * 调节屏幕亮度
   * 
   * @param paramInt 0-255
   * @return
   */
  public final static void setScreenBrightness(Activity activity, int paramInt) {
    Window localWindow = activity.getWindow();
    WindowManager.LayoutParams localLayoutParams = localWindow.getAttributes();
    float f = paramInt / 255.0F;
    localLayoutParams.screenBrightness = f;
    localWindow.setAttributes(localLayoutParams);
  }
}
